#include <Architect.hpp>
#include "WorkingMiddleFloor.hpp"
#include <math.h>

WorkingMiddleFloor::WorkingMiddleFloor()
{
  style = CLASSIC; // a titre d'exemple
}

void WorkingMiddleFloor::setBuiltIn()
{
  bv = new AABB(height, width, depth);
  
  Box* ceiling = new Box(0.3, width, depth);
  ceiling->translateOf(0, 0, height-0.3);
  addObject(ceiling);
  
  float width_begin = (width-floor(width))/2;
  
  Box* b_l1 = new Box(height-0.3, width_begin+0.1, 0.3);
  addObject(b_l1);
  
  Box* b_l2 = new Box(height-0.3, width_begin+0.1, 0.3);
  b_l2->translateOf(0, depth-0.3, 0);
  addObject(b_l2);
  
  float i;
  for (i=width_begin; i<=(width-1); i++)
  {	
    Box* b1 = new Box(0.1, 0.9, 0.3);
    b1->translateOf(i+0.1, 0, 0.8);
    addObject(b1);
	
	Plane* p1 = new Plane(0.9, 0.8, true);
	p1->translateOf(i+0.1, 0, 0);
    p1->rotateOf(90, 0, 0);
    p1->setTransparency(0.8);
    addObject(p1);
	
    Box* b2 = new Box(0.1, 0.9, 0.3);
    b2->translateOf(i+0.1, 0, 2.2);
    addObject(b2);
	
	Plane* p2 = new Plane(0.9, 1.3, true);
	p2->translateOf(i+0.1, 0, 0.9);
    p2->rotateOf(90, 0, 0);
    p2->setTransparency(0.8);
    addObject(p2);
	
	Plane* p3 = new Plane(0.9, 0.4, true);
	p3->translateOf(i+0.1, 0, 2.3);
    p3->rotateOf(90, 0, 0);
    p3->setTransparency(0.8);
    addObject(p3);
	
    Box* b4 = new Box(0.1, 0.9, 0.3);
    b4->translateOf(i+0.1, depth-0.3, 0.8);
    addObject(b4);
	
	Plane* p4 = new Plane(0.9, 0.8, true);
	p4->translateOf(i+1, depth, 0.8);
    p4->rotateOf(90, 0, 180);
    p4->setTransparency(0.8);
    addObject(p4);
	
    Box* b5 = new Box(0.1, 0.9, 0.3);
    b5->translateOf(i+0.1, depth-0.3, 2.2);
    addObject(b5);
	
	Plane* p5 = new Plane(0.9, 1.3, true);
	p5->translateOf(i+1, depth, 2.2);
    p5->rotateOf(90, 0, 180);
    p5->setTransparency(0.8);
    addObject(p5);
	
	Plane* p6 = new Plane(0.9, 0.4, true);
	p6->translateOf(i+1, depth, 2.7);
    p6->rotateOf(90, 0, 180);
    p6->setTransparency(0.8);
    addObject(p6);
	
	if (i != width_begin)
	{
	  Box* b7 = new Box(height-0.3, 0.1, 0.3);
	  b7->translateOf(i, 0, 0);
	  addObject(b7);
	  Box* b8 = new Box(height-0.3, 0.1, 0.3);
	  b8->translateOf(i, depth-0.3, 0);
	  addObject(b8);
	}
  }
  
  Box* b_r1 = new Box(height-0.3, width-i, 0.3);
  b_r1->translateOf(i, 0, 0);
  addObject(b_r1);
  
  Box* b_r2 = new Box(height-0.3, width-i, 0.3);
  b_r2->translateOf(i, depth-0.3, 0);
  addObject(b_r2);
  
  float depth_begin = (depth-0.6-floor(depth-0.6))/2;
  
  for (i=0.2; i<=(depth-1.3); i++)
  {
    Box* b1 = new Box(0.1, 0.3, 0.9);
    b1->translateOf(0, i+0.1, 0.8);
    addObject(b1);
	
	Plane* p1 = new Plane(0.9, 0.8, true);
	p1->translateOf(0, i+0.1, 0);
    p1->rotateOf(90, 90, 0);
    p1->setTransparency(0.8);
    addObject(p1);
	
    Box* b2 = new Box(0.1, 0.3, 0.9);
    b2->translateOf(0, i+0.1, 2.2);
    addObject(b2);
	
	Plane* p2 = new Plane(0.9, 1.3, true);
	p2->translateOf(0, i+0.1, 0.9);
    p2->rotateOf(90, 90, 0);
    p2->setTransparency(0.8);
    addObject(p2);
	
	Plane* p3 = new Plane(0.9, 0.4, true);
	p3->translateOf(0, i+0.1, 2.3);
    p3->rotateOf(90, 90, 0);
    p3->setTransparency(0.8);
    addObject(p3);
    
    Box* b4 = new Box(0.1, 0.3, 0.9);
    b4->translateOf(width-0.3, i+0.1, 0.8);
    addObject(b4);
	
	Plane* p4 = new Plane(0.9, 0.8, true);
	p4->translateOf(width, i+1, 0.8);
    p4->rotateOf(90, 90, 180);
    p4->setTransparency(0.8);
    addObject(p4);
    
    Box* b5 = new Box(0.1, 0.3, 0.9);
    b5->translateOf(width-0.3, i+0.1, 2.2);
    addObject(b5);
	
	Plane* p5 = new Plane(0.9, 1.3, true);
	p5->translateOf(width, i+1, 2.2);
    p5->rotateOf(90, 90, 180);
    p5->setTransparency(0.8);
    addObject(p5);
	
	Plane* p6 = new Plane(0.9, 0.4, true);
	p6->translateOf(width, i+1, 2.7);
    p6->rotateOf(90, 90, 180);
    p6->setTransparency(0.8);
    addObject(p6);
	
	if (i != depth_begin)
	{
	  Box* b7 = new Box(height-0.3, 0.3, 0.1);
	  b7->translateOf(0, i, 0);
	  addObject(b7);
	  Box* b8 = new Box(height-0.3, 0.3, 0.1);
	  b8->translateOf(width-0.3, i, 0);
	  addObject(b8);
	}
  }
  
  Box* b_r3 = new Box(height-0.3, 0.3, depth-i);
  b_r3->translateOf(0, i, 0);
  addObject(b_r3);
  
  Box* b_r4 = new Box(height-0.3, 0.3, depth-i);
  b_r4->translateOf(width-0.3, i, 0);
  addObject(b_r4);
}
